﻿package com.xuanque.mahjongDice.control 
{
	//import com.xuanque.mahjongDice.data.Player;
	import com.xuanque.mahjongDice.Main;
	import com.xuanque.mahjongDice.display.*;
	
	import datas.Player;
	
	import utils.HashMap;
	
	/**
	 * ...
	 * @author DefaultUser (Tools -> Custom Arguments...)
	 */
	public class GameController 
	{
		
		private static var Instance:GameController = new GameController();
		
		/*
		 * 单件类的实例 
		*/
		public static function getInstance():GameController {
			
			return Instance;
		}
		
		
		public function getConnect():void {
			
		}
		
		/*
		 * 第一次进入游戏,初始化用户界面
		*/
		public static function enterGame(players:Array):void {
			
			
			GameAction.getInstance().enterGame(players);
		}
		
		
		/*
		 * 某一用户加入游戏
		*/
		public static function addGame(player:Player):void {
			
			GameAction.getInstance().addGame(player);
		}
		
		
		
		//离开游戏，更改界面 (包括本人和其它用户)
		public static function leaveGame(player:Player):void {
			
			GameAction.getInstance().leaveGame(player);
		}
		
		
		
		/*
		 * 设置玩家准备状态
		*/
		public static function setUserReady(username:String):void{
		    
			GameAction.getInstance().setUserReady(username);
		}
		
		//玩家取消准备
		public static function cancelUserReady(username:String):void {
			
			GameAction.getInstance().cancelUserReady(username);
		}
		
		
		
		
		
		
		
		
		
		
		/*
		 * 确定庄家 ( 发牌后第一个摇 )
		*/
		public static function host(username:String):void{
			
			GameAction.getInstance().host(username);
			
		}
		
		
		
		
		/*
		 * 首发骰给各个玩家 ( 所有 位置 、 牌  )  
		*/ 
		public static function gameStart( _dices:Array ):void {
			
			GameAction.getInstance().gameStart( _dices );
			
			
			
		}
		
		
		
		/*
		 * 开始发牌
		*/
		public static function typeOutControl():void {
			
			GameAction.getInstance().typeOutControl();
		}
		
		
		
		/*
		 * 打公骰	
		*/
		public static function getSystemPai(num:uint):void {
			
			GameAction.getInstance().getSystemPai(num);
			
		}
		
		
		/*
		 * 打骰 接力
		*/
		public static function priority(username:String):void {
			
		  GameAction.getInstance().priority(username);
		  
		}
		
		
		/*
		 * 通知摇出的骰 ( 显示 取得的 牌 )
		*/
		public static function displayGetPai(username:String, pai:int):void {
			
			
			//trace("通知摇出的骰 ( 显示 取得的 牌 ) username====" + username + "pai ====" + pai);
			
			//GameAction.getInstance().displayGetPai(username,pai);
			GameAction.getInstance().getPaiYaoSai( username,pai ); //取牌 摇骰 后显示牌
			
		}
		
		
		/*
		 * 出骰通知 ( 显示 发出去的 牌 )
		*/
		public static function displayOutPai(username:String, pai:int):void{
			
			//trace("出骰通知 ( 显示 发出去的 牌 ) username====" + username + "pai ====" + pai);
			
			GameAction.getInstance().displayOutPai(username, pai);
			
		}
		
		
		
		/*
		 * 胡牌验证
		*/
		public static function huPaiTip(username:String,status:int = 0):void {
			
			GameAction.getInstance().huPaiTip(username,status);
			
		}
		
		
		
		
		
		
		
		
		
		/*
		 * 结算结果
		*/
		public static function showResults(result_array:Array):void {
			
			GameAction.getInstance().showResults(result_array);
			
		}
		
		/*
		 * 游戏结束，可以重新开始
		*/
		public static function gameOver():void {
			
			GameAction.getInstance().gameOver();
		}
		
		
		
		
		/*
		 * 强行退出游戏,断线
		*/
		public static function outOfGame(username:String ,isout:Boolean = true ):void{
			
			GameAction.getInstance().outOfGame(username, isout);
			
		}
		
		
		
		public static function init():void{
			
			Main.getInstance().init();
			Main.getInstance().addListener();
			
		}
		
		
		/*
		 * 断线重连设置 userInfos 里包含所有Player 和 info数组
		*/
		public static function resetScene( userInfos:HashMap ):void {
			
			trace("userInfos=" + userInfos.values());
			trace("GameAction.getInstance()=" + GameAction.getInstance());
			
			GameAction.getInstance().resetScene( userInfos );
			
		}
		
		/*
		 * 断线的人回来
		*/		
		public static function userComeBack(player:Player):void {
			
			GameAction.getInstance().userComeBack( player );
			
		}
		
		
		/*
		 * 断线回来设置最新状态
		*/
		public static function resetNewestStatus(isPub:int,pos:int ):void {
			
			trace("断线回来设置最新状态 pos === " + pos + "GameAction.getInstance() === " + GameAction.getInstance() );
			GameAction.getInstance().resetNewestStatus(isPub,pos );
		}
		
		//重构公共牌
		//public function resetPubCards(pCards:Array):void {
			
			//CoreAction.getInstance().resetPubCards(pCards);
		//}
		
		
		
		
		
		/*
		 * 托管(是否)
		*/
		public static function trusteeship(username:String,istrue:Boolean = true):void {
			
			GameAction.getInstance().trusteeship(username ,istrue );
		}
		
		
		/*
		 * 更新某一用户列表
		*/
		public static function updateUser(player:Player):void {
			
			GameAction.getInstance().updateUser(player);
		}
		
		
		/*
		 * 更新信号
		*/
		public static function updateSignal():void {
			if(GameAction.getInstance())
			//trace("更新网络信号");
			GameAction.getInstance().updateSignal();
			
		}
		
		/*
		 * 接收聊天信息
		*/
		public static function chating(username:String, content:String):void {
			
			GameAction.getInstance().chating(username,content);
			
		}
		
		
		
		/*
		 * 把不必要的引用设为null
		*/
		public static function setStaticObjectNull():void {
			
			GameAction.getInstance().setStaticObjectNull();
			
			 Instance = null;
		}
		
		
		
		
		
		
	}
	
}